package com.yayohos.locationmanager.helper;


import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * 日志工具类
 */
public final class LogUtils {
    private static final int TRACE_INDEX = 4;
    private static final int LOG_DOMAIN = 23333;
    private static boolean isEnabled = false;

    private LogUtils() {
    }

    /**
     * 是否启用Log打印
     *
     * @param isEnabled 是否启用
     */
    public static void enable(boolean isEnabled) {
        LogUtils.isEnabled = isEnabled;
    }


    /**
     * logE
     *
     * @param message 日志信息
     */
    public static void logE(String message) {
        if (isEnabled) {
            HiLog.error(getHiLogLabel(), message);
        }
    }

    /**
     * logI
     *
     * @param message 日志信息
     */
    public static void logI(String message) {
        if (isEnabled) {
            HiLog.info(getHiLogLabel(), message);
        }
    }


    private static HiLogLabel getHiLogLabel() {
        StackTraceElement[] trace = Thread.currentThread().getStackTrace();
        StackTraceElement relevantTrace = trace[TRACE_INDEX];
        String className = relevantTrace.getClassName();
        int lastIndex = className.lastIndexOf('.');
        return new HiLogLabel(HiLog.LOG_APP, LOG_DOMAIN, "23333" + className.substring(lastIndex));
    }
}